﻿using System.Collections.Generic;
using System;
using System.Data;
using JZ.JiangSu.Model.Entity;
using System.Collections;

namespace JZ.JiangSu.IRepository
{
    //接口抽象的并不是很好  抽象接口应支持多数据库多类型框架 
    public interface IBaseRepository<T> where T : BaseEntity
    {
        #region 基础接口-其他接口调用这几个完成实现
        /// <summary>
        /// 添加一个记录
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns></returns>
        int Add(T entity);
        /// <summary>
        /// 自定义条件删除记录
        /// </summary>
        /// <param name="whereCondition">where条件</param>
        /// <returns></returns>
        int Delete(string whereCondition);
        /// <summary>
        /// 更新一条记录
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns></returns>
        int Update(T entity);

        int AutoUpdate(Hashtable ht);

        /// <summary>
        /// 自定义条件和内容更新记录
        /// </summary>
        /// <param name="fieldsSet"></param>
        /// <param name="whereCondition"></param>
        /// <returns></returns>
        int Update(string fieldsSet, string whereCondition);
        /// <summary>
        /// 根据条件获取实体对象
        /// </summary>
        /// <param name="whereCondition">where条件</param>
        /// <returns></returns>
        List<T> GetEntities(string whereCondition);

        /// <summary>根据条件查询
        /// 自动生成SQL
        /// </summary>
        /// <param name="ht"></param>
        /// <returns></returns>
        IList<T> AutoGetEntity(Hashtable ht);

        /// <summary>
        /// 分页获取数据
        /// </summary>
        /// <param name="startRow">起始行号</param>
        /// <param name="endRow">终止行号</param>
        /// <param name="sortConditionDic">排序依据字典(字段名,排序规则)</param>
        /// <param name="whereCondition">查询的where条件</param>
        /// <param name="totalCount">总记录数</param>
        /// <returns></returns>
        List<T> GetPagedEntities(int startRow, int endRow, Dictionary<string, Model.Enum.SortEnum> sortConditionDic, string whereCondition, out int totalCount);
        /// <summary>
        /// 获取对应查询条件下记录的条数
        /// </summary>
        /// <param name="whereCondition">查询where条件，可以为空</param>
        /// <returns></returns>
        int GetTotalCount(string whereCondition);

        ///// <summary>
        ///// 获取对应查询条件下记录的条数
        ///// </summary>
        ///// <param name="ht">条件参数</param>
        ///// <returns></returns>
        //int GetNeedInfoTotals(Hashtable ht);
        #endregion

        /// <summary>
        /// 删除一个记录
        /// </summary>
        /// <param name="id">该记录的主键Id</param>
        /// <returns></returns>
        int Delete(int id);
        /// <summary>
        /// 删除一多个记录
        /// </summary>
        /// <param name="idList">多个记录的主键Id的集合</param>
        /// <returns></returns>
        int Delete(IList<int> idList);

        /// <summary>
        /// 更新N个记录的M个字段值
        /// </summary>
        /// <param name="entityIdList">多个记录的主键Id的集合</param>
        /// <param name="modifyFields">要更新字段的字段名与结果值的字典集合</param>
        /// <returns></returns>
        int Update(IList<int> entityIdList, Dictionary<string, object> modifyFields);
        /// <summary>
        /// 通过Id获取Resume
        /// </summary>
        /// <param name="entityId"></param>
        /// <returns></returns>
        T GetEntityById(int entityId);
        /// <summary>
        /// 通过Id集合获取Resume集合
        /// </summary>
        /// <param name="entitiesIds">id集合</param>
        /// <returns></returns>
        List<T> GetEntitiesByIds(IList<int> entitiesIds);
        /// <summary>
        /// 获取全部记录
        /// </summary>
        /// <returns></returns>
        List<T> GetAllEntities();
        /// <summary>
        /// 得到运行时ibatis.net动态生成的SQL
        /// </summary>
        /// <param name="statementName"></param>
        /// <param name="t"></param>
        /// <returns></returns>
        Tuple<string, IDbDataParameter[]> GetSql(string statementName, T t);

    }
}